/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.gbeine.java.depview.ui.component;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.AbstractListModel;

/**
 *
 * @author gbeine
 */
final class FilterListModel extends AbstractListModel {

    /**
     *
     */
    private static final long serialVersionUID = -3373984359113343266L;
    /**
     *
     */
    private final List<String> filterStrings = new ArrayList<String>();

    /**
     *
     */
    public FilterListModel() {
        super();
    }

    /**
     *
     * @param element
     */
    public void addElement(final String element) {
        this.filterStrings.add(element);
        this.contentsChanged();
    }

    /**
     *
     * @param pElements
     */
    public void addElements(final Collection<String> pElements) {
        this.filterStrings.addAll(pElements);
        this.contentsChanged();
    }

    /**
     *
     * @param s
     */
    public void removeElement(final String s) {
        this.filterStrings.remove(s);
        this.contentsChanged();
    }

    @Override
    public int getSize() {
        return this.filterStrings.size();
    }

    @Override
    public Object getElementAt(final int i) {
        return this.filterStrings.get(i);
    }

    /**
     *
     */
    private void contentsChanged() {
        this.fireContentsChanged(this, 0, this.filterStrings.size() - 1);
    }
}
